#ifndef UI
#define UI
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h>

#ifdef __APPLE__
#include <termios.h>
#include <unistd.h>
#define KEY_UP 'w'
#define KEY_DOWN 's'
#define KEY_ESC 27
#define KEY_ENTER ' '
int _getch();
#elif defined(__linux__)
#include <termios.h>
#include <unistd.h>
#define KEY_UP 'w'
#define KEY_DOWN 's'
#define KEY_ESC 27
#define KEY_ENTER ' '
int _getch();
#else
#include <conio.h>
#include <windows.h>
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_ESC 27
#define KEY_ENTER 13
#endif



enum UIType
{
    UI_str,
    UI_selector
};

enum VarType
{
    _str,
    _int,
    _float,
    _conststring,
    _bool
};

struct UIElement
{
    std::string (*datastr);
    std::string _conststring;
    int (*dataint);
    float (*datafloat);
    bool (*databool);
    VarType type;
    int wordcolor;
    int backgroundcolor;
};

class _UI
{
public:
    _UI();
    void show();
    std::vector<std::vector<UIElement>> data;
    UIType type;
    int selectNum;
    int specialSelector;
   
    void addconststring(std::string _data,bool _endl = 0, int wordcolor = 0, int backgroundcolor = 0);
    void addstr(std::string (*_data),bool _endl = 0, int wordcolor = 0, int backgroundcolor = 0);
    void addfloat(float (*_data),bool _endl = 0, int wordcolor = 0, int backgroundcolor = 0);
    void addint(int (*_data),bool _endl = 0, int wordcolor = 0, int backgroundcolor = 0);
    void addbool(bool (*_data),bool endl = 0, int wordcolor = 0, int backgroundcolor = 0);
    void clear();
private:
    //颜色为B1 G2 R4 w8
    void setcolor(int wordcolor = 0, int backgroundcolor = 0);
    void resetcolor();
    bool LineCompleteFlag = 1;
};

int KeyboardOperate();
void clearUI();
void PrintUI(std::vector<_UI>);

#endif